package com.mingsoft.led.comm;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class CommServer extends Thread {
	public CommServer() {
		this.start();
	}

	public void run() {
		ServerSocket server = null;
		try {
			server = new ServerSocket(65500);
			System.out.println("start server at 65500");
			while (true) {
				Socket socket = server.accept();
				System.out.println("new terminal received");
				CommThread ct = new CommThread(socket);
				ct.start();
				try {
					sleep(1000);
				} catch (InterruptedException e1) {
				}
				while (ct.isRunning()) {
					try {
						sleep(100);
					} catch (InterruptedException e) {
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (server != null) {
				try {
					server.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				server = null;
			}
		}
	}
}
